<template>
   <div class="images-list">
    <div class="upload-list" :class="{'active':showMore}" v-if="curType==1">
        <div class="upload-list-item" :class="{'active':item.ischecked}" v-for="(item,index) in fileList" :key="index+5">
            <div class="list-item-content">
              <div class="item-top">
                <el-checkbox v-model="item.ischecked"></el-checkbox>
              </div>
              <div class="item-bottom">
                <!-- <img src="../assets/images/icon-no-image.png" class='default'> -->
                <img :src="item.url" class='img'>
                <div class="mark"></div>
                <span class="el-upload-list__item-actions-content">
                  <span
                    class="el-upload-preview"
                    @click="handlePictureCardPreview(item.url)"
                  >
                    <i class="el-icon-zoom-in"></i>
                  </span>
                
                  <span
                    class="el-upload-delete"
                    @click="handleRemove(1,index)"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </div>
        </div>
        <div class="upload-list-item" :class="{'active':item.ischecked}" v-for="(item,index) in fileList2" :key="index+66">
            <div class="list-item-content">
              <div class="item-top">
                <el-checkbox v-model="item.ischecked"></el-checkbox>
                <span class="text">3D</span>
              </div>
              <div class="item-bottom">
                <img :src="item.url" class='img' v-if="item.url">
                <img src="../assets/images/icon-no-image.png" v-else class='default'>

                <div class="mark"></div>
                <span class="el-upload-list__item-actions-content">
                  <span
                    class="el-upload-preview"
                    @click="handlePictureCardPreview2(item)"
                  >
                      <img src="../assets/images/icon-3D.png" class="icon-3d">
                  </span>
                  <span
                    class="el-upload-delete"
                    @click="handleRemove(2,index)"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </div>
        </div>
        <div v-show="imgListNum>5" class="up-down-btn" @click="showMore = !showMore">
          <p>{{showMore?'收起':'展开'}}</p>
          <p>全部</p>
          <p class="el-icon-d-arrow-left icon_item--arrow" :class="{'active':!showMore}"></p>
        </div>
    </div>
    <div class="image-content" v-else>
      <div class="image-item item-3d" >
        <el-image
            style="width: 120px; height: 120px"
            src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
            fit="cover"></el-image>
            <img src="../assets/images/icon-3D.png" class="icon-3d">
            <span class="desc-image-3d">点击查看三维图</span>
      </div>

      <div class="image-item item-icon" @click="handlePictureCardPreview('https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg')">
        <el-image
            style="width: 120px; height: 120px"
            src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
            fit="cover"></el-image>
            <i class="el-icon-zoom-in icon-item"></i>
      </div>
      <div class="image-item item-icon">
        <el-image
            style="width: 120px; height: 120px"
            src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
            fit="cover"></el-image>
            <i class="el-icon-zoom-in icon-item"></i>
      </div>
    </div>
    <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
   </div>
</template>
<script>
import { ref, reactive, onMounted, computed ,toRefs,watch,nextTick } from "@vue/composition-api";

export default {
    setup(props, { root,emit  } ){ 
      console.log(props) 
      let datas = reactive({
        dialogImageUrl:'',
        dialogVisible: false,
        showMore:false,
        imgListNum: computed(() => props.fileList.length + props.fileList2.length) 
      });
      const handleRemove = (type,idx)=> {
        root.$confirm("确定删除吗？", "删除确认", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          showClose: false,
          type: "warning",
          center: true,
          customClass: "common-confirm-box",
          confirmButtonClass: "common-btn-primary",
          cancelButtonClass: "common-btn-text",
        }).then(() => {
           emit('deleteImage',{idx,type})
        });
      };
     const handlePictureCardPreview = (url)=> {
       console.log(url)
        datas.dialogImageUrl = url;
        datas.dialogVisible = true;
     };
     const handlePictureCardPreview2 = (item)=> {
        datas.dialogImageUrl = item.url;
        datas.dialogVisible = true;
     };
      return {
        ...toRefs(datas),props,handleRemove,handlePictureCardPreview,handlePictureCardPreview2,
      }
    },
  props: {
    fileList: {
      type: Array,
      default:() => []
    },
    fileList2: {
      type: Array,
      default:() => []
    },
    curType: {
      type: Number,
      default:() => 1
    }
  },
};
</script>
<style scoped>
/* 展示图片内容  start*/
.upload-list{
  position: relative;
  margin-left: 190px;
  height: 160px;
  overflow: hidden;
}
.upload-list.active{
  height: auto;
  overflow: visible;
}

.upload-list-item {
  width: 160px;
  height: 160px;
  display: inline-block;
  border:1px solid #ccc;
  border-radius:5px;
  margin: 0 10px 10px 0;
}
.upload-list-item.active {
  border-color: #4972E8;
}
.list-item-content {
  width: 160px;
  height: 160px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.item-top {
  display: flex;
  padding: 10px;
  justify-content: space-between;
}
.item-bottom {
  height: 119px;
  width: 158px;
  overflow: hidden;
  position: relative;
}
.item-bottom .img{
  width: 158px;
  height: 119px;
  object-fit: cover;
}

.mark {
  position: absolute;
  width:100%;
  height:100%;
  background: rgba(0,0,0,.6);
  left: 0;
  top: 0;
  display:none;
}
.item-bottom:hover .mark{
  display:block;
}
.el-upload-list__item-actions-content{
    position: absolute;
    top: 47px;
    width: 86%;
    color: #fff;
    font-size: 20px;
    display:none;
}
.el-upload-preview {
  padding: 0 50px 0 36px;
}
.item-bottom:hover .el-upload-list__item-actions-content{
  cursor: pointer;
  display:block;
}

.item-bottom .default{
    width: 73px;
    height: 92px;
    margin: 0 auto;
    display: block;
}
.item-bottom .icon-3d{
    position: relative;
    width: 22px;
    top: 3px;
}

.up-down-btn{
  position: absolute;
  right:8px;
  top:0;
  padding-top: 50px;
  width: 40px;
  height:160px;
  text-align: center;
  background-color: #ECF0FC;
  border:1px solid #BBC9F6;
  border-radius: 4px;
  color:#557BEA;
  cursor: pointer;
}
.icon_item--arrow {
    margin-top: 10px;
    transform: rotate(90deg);
    font-size: 17px;
    font-weight: bold;
}
.icon_item--arrow.active {
    transform: rotate(-90deg);
}
/* 展示图片内容  end*/


/* 查看页图片展示 */
.image-content{
     margin-left: 214px;
  }
  .image-item {
    position:relative;
    display: inline-block;
    margin:0 12px 10px 0;
  }
  .desc-image-3d {
    position: absolute;
    left:0;
    bottom:-20px;
    width:100%;
    text-align: center;
  }
  .item-3d .icon-3d {
    position: absolute;
    left: 45px;
    top: 51px;
    width: 30px;
    text-align: center;
    display: inline-block;
    background-color: rgba(0,0,0,0.2);
    border-radius: 20%;
    display:none;
  }
  .item-3d:hover .icon-3d {
    display: block;
    cursor: pointer;
  }
  .item-icon .icon-item {
    position: absolute;
    left: 45px;
    top: 51px;
    text-align: center;
    color:#fff;
    font-size: 20px;
    display:none;
  }
  .item-icon:hover .icon-item {
    display: block;
  }
  .item-icon:hover {
    cursor: pointer;
  }
</style>
